<template>
	<view class="classList pageBg">
		<view class="loadingLayout" v-if="!classList.length && !noData">
			<uni-load-more status="loading"></uni-load-more>
		</view>
		<view class="content">
			<navigator :url="'/pages/preview/preview?id='+item.id" class="item" v-for="item in classList">
				<image :src="item.pic" mode="aspectFill"></image>
			</navigator>
		</view>
		<view class="loadingLayout" v-if="classList.length || noData">
			<uni-load-more :status="noData?'noMore':'loading'"></uni-load-more>
		</view>
		<view class="safe-area-inset-buttom"></view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { onReady, onLoad, onReachBottom } from '@dcloudio/uni-app'
import { apiGetImageByClassify } from '@/api/apis';

const classList = ref([]);
const currentLabel = ref("西安");
const noData = ref(false);
const queryParams = {
	pageNum:1,
	pageSize:12
}
// 获取分类列表
const getClassList = async() => {
	let res = await apiGetImageByClassify(currentLabel.value, queryParams);
	classList.value = [...classList.value, ...res.data];
	if(queryParams.pageSize > res.data.length) noData.value = true;
	uni.setStorageSync("storageClassList", classList.value)
}
onLoad((e)=>{
	let {label=null} = e;
	currentLabel.value = label;
	uni.setNavigationBarTitle({
		title:label
	});
	getClassList();
})
onReachBottom(() => {
	if(noData.value) return;
	// console.log("dfasdfasfdasfdasfdsads")
	queryParams.pageNum++;
	getClassList();
})

// onReady(() => {
// 	getClass();
// })
</script>

<style lang="scss" scoped>
.classList{
	.content{
		display: grid;
		grid-template-columns: repeat(3,1fr);
		gap:5rpx;
		padding: 5rpx;
		.item{
			height: 440rpx;
			image{
				width: 100%;
				height: 100%;
				display: block;
			}
		}
	}
}
</style>
